﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace tamlytre.Admin
{
    public partial class Admin : System.Web.UI.MasterPage
    {
        DBTuVanDataContext db = new DBTuVanDataContext();
        public static TB_User taiKhoan = null;
        public void CollectData()
        {
            taiKhoan = (TB_User)Session["TaiKhoan"];
            if (taiKhoan == null || taiKhoan.Role != 1)
                Response.Redirect("../Admin/LoginAdmin.aspx");
            else
            {
                LabelWelcome.Text = string.Format("Chào Admin <strong class='admin_name'>{0}</strong>", taiKhoan.UserName);
            }
        }
        public void LoadMenu()
        {
            try
            {
                List<TB_Catagory> mainmenu = db.USP_MenuAdminParent().ToList();
                rptMainMenuParent.DataSource = mainmenu;
                rptMainMenuParent.DataBind();
            }
            catch
            { 
            }
        }
        protected void rptMainMenuParent_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            try
            {
                HiddenField hrId = (HiddenField)e.Item.FindControl("hrID"); //--- day la Id cua loai san pham A---

                Repeater rpChildrent = e.Item.FindControl("rptMainMenuChild") as Repeater;

                if (hrId != null && rpChildrent != null)
                {
                    int id = Convert.ToInt32(hrId.Value.ToString().Trim());
                    List<TB_Catagory> menuchild = db.USP_MainMenuChild(id).ToList();
                    rpChildrent.DataSource = menuchild;
                    rpChildrent.DataBind();
                }
            }
            catch
            { }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadMenu();
                CollectData();
                SetTime();
            }
        }
        protected void Timer_Tick(object sender, EventArgs e)
        {
            UpdatePanelTime.Update();
        }
        public void SetTime()
        {
            LabelTime.Text = string.Format("<strong class='sys_time'>{0}</strong> ngày {1} tháng {2} năm {3}",
                DateTime.Now.ToString("HH : mm"), DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year);
        }
        protected void LinkButtonLogut_Click(object sender, EventArgs e)
        {
            Session.Abandon();
            Response.Redirect("../Default.aspx");
        }
    }
}